﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using YuuzleComic.Model;
using YuuzleComic.DALFactory;
using YuuzleComic.IDAL;
namespace YuuzleComic.BLL
{
	/// <summary>
	/// cjxm
	/// </summary>
	public partial class cjxm
	{
		private readonly Icjxm dal=DataAccess.Createcjxm();
		public cjxm()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			return dal.Exists(id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(YuuzleComic.Model.cjxm model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(YuuzleComic.Model.cjxm model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			return dal.Delete(id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			return dal.DeleteList(idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public YuuzleComic.Model.cjxm GetModel(int id)
		{
			
			return dal.GetModel(id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public YuuzleComic.Model.cjxm GetModelByCache(int id)
		{
			
			string CacheKey = "cjxmModel-" + id;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(id);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (YuuzleComic.Model.cjxm)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<YuuzleComic.Model.cjxm> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<YuuzleComic.Model.cjxm> DataTableToList(DataTable dt)
		{
			List<YuuzleComic.Model.cjxm> modelList = new List<YuuzleComic.Model.cjxm>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				YuuzleComic.Model.cjxm model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new YuuzleComic.Model.cjxm();
					if(dt.Rows[n]["id"].ToString()!="")
					{
						model.id=int.Parse(dt.Rows[n]["id"].ToString());
					}
					model.xmmc=dt.Rows[n]["xmmc"].ToString();
					if(dt.Rows[n]["xmfd"].ToString()!="")
					{
						if((dt.Rows[n]["xmfd"].ToString()=="1")||(dt.Rows[n]["xmfd"].ToString().ToLower()=="true"))
						{
						model.xmfd=true;
						}
						else
						{
							model.xmfd=false;
						}
					}
					if(dt.Rows[n]["picxz"].ToString()!="")
					{
						if((dt.Rows[n]["picxz"].ToString()=="1")||(dt.Rows[n]["picxz"].ToString().ToLower()=="true"))
						{
						model.picxz=true;
						}
						else
						{
							model.picxz=false;
						}
					}
					if(dt.Rows[n]["xmsx"].ToString()!="")
					{
						model.xmsx=int.Parse(dt.Rows[n]["xmsx"].ToString());
					}
					model.cjurl=dt.Rows[n]["cjurl"].ToString();
					model.fnbody=dt.Rows[n]["fnbody"].ToString();
					model.fnfg=dt.Rows[n]["fnfg"].ToString();
					model.fnid=dt.Rows[n]["fnid"].ToString();
					model.fnmc=dt.Rows[n]["fnmc"].ToString();
					model.mhurl=dt.Rows[n]["mhurl"].ToString();
					model.mhbody=dt.Rows[n]["mhbody"].ToString();
					model.mhmc=dt.Rows[n]["mhmc"].ToString();
					model.mhtp=dt.Rows[n]["mhtp"].ToString();
					model.mhtpurl=dt.Rows[n]["mhtpurl"].ToString();
					model.mhzz=dt.Rows[n]["mhzz"].ToString();
					model.mhjs=dt.Rows[n]["mhjs"].ToString();
					model.mhzt=dt.Rows[n]["mhzt"].ToString();
					model.mhfg=dt.Rows[n]["mhfg"].ToString();
					model.mhzj=dt.Rows[n]["mhzj"].ToString();
					model.wj=dt.Rows[n]["wj"].ToString();
					model.lz=dt.Rows[n]["lz"].ToString();
					model.mhzjid=dt.Rows[n]["mhzjid"].ToString();
					model.zjurl=dt.Rows[n]["zjurl"].ToString();
					model.zjbody=dt.Rows[n]["zjbody"].ToString();
					if(dt.Rows[n]["zjsx"].ToString()!="")
					{
						model.zjsx=int.Parse(dt.Rows[n]["zjsx"].ToString());
					}
					model.zjfy=dt.Rows[n]["zjfy"].ToString();
					if(dt.Rows[n]["zjtpurlsx"].ToString()!="")
					{
						model.zjtpurlsx=int.Parse(dt.Rows[n]["zjtpurlsx"].ToString());
					}
					model.zjtpsl=dt.Rows[n]["zjtpsl"].ToString();
					model.zjtpsurl=dt.Rows[n]["zjtpsurl"].ToString();
					model.zjtpurl=dt.Rows[n]["zjtpurl"].ToString();
					model.gxurl=dt.Rows[n]["gxurl"].ToString();
					model.gxbody=dt.Rows[n]["gxbody"].ToString();
					model.gxfg=dt.Rows[n]["gxfg"].ToString();
					model.gxmc=dt.Rows[n]["gxmc"].ToString();
					model.gxid=dt.Rows[n]["gxid"].ToString();
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

